package com.li.youhappygo.controller;

import com.github.pagehelper.PageInfo;
import com.li.youhappygo.annotation.Log;
import com.li.youhappygo.annotation.OperatorType;
import com.li.youhappygo.model.entity.commond.Brand;
import com.li.youhappygo.model.entity.commond.BrandCategory;
import com.li.youhappygo.model.vo.category.CategoryBrandVo;
import com.li.youhappygo.model.vo.common.Result;
import com.li.youhappygo.model.vo.common.ResultCode;
import com.li.youhappygo.service.CategoryBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/categoryBrand/")
@Tag(name = "分类品牌管理", description = "分类品牌管理")
public class CategoryBrandController {
    @Autowired
    CategoryBrandService categoryBrandService;

    @GetMapping("/getCategoryBrand/{pageNum}/{pageSize}")
    @Operation(summary = "查询所有分类品牌信息",description = "分页查询所有品牌与类别的信息，返回PageInfo")
    public Result<PageInfo<CategoryBrandVo>> getCategoryBrand(@PathVariable Integer pageNum, @PathVariable Integer pageSize, BrandCategory brandCategory) {
        PageInfo<CategoryBrandVo> pageInfo =  categoryBrandService.getCategoryBrand(pageNum, pageSize,brandCategory);
        return Result.build(pageInfo, ResultCode.SUCCESS);
    }

    @PostMapping("insertCategoryBrand/")
    @Operation(summary = "插入一个品牌与分类的关系",description = "这里就是给分类加个品牌，只需要提供品牌和分类的ID")
    @Log(title = "插入一个分类品牌", businessType = 1,operatorType = OperatorType.MANAGE)
    public Result insertCategoryBrand(@RequestBody BrandCategory brandCategory) {
        categoryBrandService.insertCategoryBrand(brandCategory);
        return Result.build(null, ResultCode.SUCCESS);
    }

    @PostMapping("/deleteCategoryBrand")
    @Operation(summary = "删除一个分类下面的品牌",description = "传入分类ID和品牌ID")
    @Log(title = "删除一个分类品牌", businessType = 3,operatorType = OperatorType.MANAGE)
    public Result deleteCategoryBrand(@RequestBody BrandCategory brandCategory) {
        categoryBrandService.deleteCategoryBrand(brandCategory);
        return Result.build(null, ResultCode.SUCCESS);
    }
    @GetMapping("/findBrandByCategoryId/{categoryId}")
    @Operation(summary = "根据分类ID查询该分类下的所有品牌",description = "传入分类ID")
    public Result<List<Brand>> findBrandByCategoryId(@PathVariable Long categoryId) {
        List<Brand> brandList = categoryBrandService.findBrandByCategoryId(categoryId);
        return Result.build(brandList , ResultCode.SUCCESS) ;
    }


}
